<template>
  <div id="departs">
    <el-card class="tree-card">
      <!-- 采用一个行列布局 -->
      <tree-tools :tree-node="company" is-root="true"></tree-tools>
      <el-tree :data="departs" :props="defaultProps" :default-expand-all="true">
        <tree-tools slot-scope="{ data }" :tree-node="data"></tree-tools>
      </el-tree>
    </el-card>
  </div>
</template>

<script>
import treeTools from "./components/tree-tools";
/* 引入管理员工接口 */
import { getDepartments } from "@/api/departments";
/* 引入二级循环 */
import { transListToTreeData } from "@/utils/index";
export default {
  components: { treeTools },
  data() {
    return {
      company: {},
      departs: [],
      defaultProps: {
        label: "name", // 表示 从这个属性显示内容
      },
    };
  },
  created() {
    this.getDepartments();
  },
  methods: {
    async getDepartments() {
      const res = await getDepartments();

      this.company = { name: res.companyName, manager: "负责人" };

      this.departs = transListToTreeData(res.depts, "");
      /* 必须添加 */
    },
  },
};
</script>

<style lang="scss" scoped>
.tree-card {
  padding: 30px 140px;
  font-size: 14px;
}
</style>
